package com.emellend.api.animation;


import com.emellend.api.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.ViewFlipper;
/**
 * 当选择下拉选框不同内容时，上方的文字以不同的动画方式交替
 * @author emellend
 *
 */
public class Animation2 extends Activity implements OnItemSelectedListener {
	private ViewFlipper mFlipper;
	private Spinner mSpinner;
	private String[] mStrings = {"Push up", "Push left", "Cross fade", "Hyperspace"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.animation_2);
		init();
	}

	private void init() {
		mFlipper = (ViewFlipper) findViewById(R.id.flipper);
		mFlipper.startFlipping();
		mSpinner = (Spinner) findViewById(R.id.spinner);
		setAdapter();
		
	}

	private void setAdapter() {
		ArrayAdapter<String> adapter=
				new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,mStrings);
		mSpinner.setAdapter(adapter);
		mSpinner.setOnItemSelectedListener(this);
	}
	
	public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
		switch (position) {
		case 0:
			mFlipper.setInAnimation(this, R.anim.push_up_in);
			mFlipper.setOutAnimation(this,R.anim.push_up_out);
			break;
		case 1:
			mFlipper.setInAnimation(this, R.anim.push_left_in);
			mFlipper.setOutAnimation(this,R.anim.push_left_out);
			break;
		case 2:
			mFlipper.setInAnimation(this,android.R.anim.fade_in);
			mFlipper.setOutAnimation(this,android.R.anim.fade_out);
			break;
		default:
			mFlipper.setInAnimation(this,R.anim.hyperspace_in);
			mFlipper.setOutAnimation(this,R.anim.hyperspace_out);
			break;
		}
		
	}
	public void onNothingSelected(AdapterView<?> parent) {}
}
